#define _CRT_SECURE_NO_WARNINGS

#include <string.h>
#include "../inc/common.h"
#include <stdio.h>

CAN_frame init(uint8_t data[8])
{
    CAN_frame frame;

    for (int i = 0; i < 8; i++) {
        frame.data[i] = data[i];
    }
    return frame;
}

void hash_xor_int(unsigned char* hash, int num, unsigned char* xor_result)
{
    int xor_temp;
    int part_result;
    memcpy(&xor_temp, hash, INT_SIZE);
    part_result = num ^ xor_temp;
    memcpy(xor_result, &part_result, INT_SIZE);
    memcpy(xor_result + INT_SIZE, hash + INT_SIZE, KEY_LENGTH_BYTES - INT_SIZE);
}

void print_hex(unsigned char* data, int length)
{
    printf("\n");
    for (int i = 0; i < length; ++i)
    {
        printf("%02x", data[i]);
    }
    printf("\n");
}

int arrayToStr(unsigned char* buf, unsigned int buflen, char* out)
{
    char strBuf[33] = { 0 };
    char pbuf[32];
    int i;
    for (i = 0; i < buflen; i++)
    {
        sprintf(pbuf, "%02X", buf[i]);
        strncat(strBuf, pbuf, 2);
    }
    strncpy(out, strBuf, buflen * 2);
    printf("out = %s\n", out);
    return buflen * 2;
}